<?php
if (! defined ( 'BASEPATH' ))
	exit ( 'No direct script access allowed' );

class Replylist extends CI_Controller {
	
	function __construct() {
		parent::__construct ();
	
	}
	
	public function index() {
		$eData = array();
		$commentId  = (int)$this->uri->segment(2);
		$type  = (int)$this->uri->segment(3);
		$ePage = ( int ) $this->input->get ('page' );
		
		
		$comment = null;
		if($type == '4'){
			$this->db->select('comment.*,member.username,member.avatar,member.id as memberId');
			$this->db->from('comment');
			$this->db->join('member', 'member.id = comment.creatid');
			$this->db->where('comment.id',$commentId);
			$comment = $this->db->get()->row_array();
		}else if($type == '5'){
			$this->db->select('topic.*,member.username,member.avatar,member.id as memberId');
			$this->db->from('topic');
			$this->db->join('member', 'member.id = topic.creatid');
			$this->db->where('topic.id',$commentId);
			$comment = $this->db->get()->row_array();
		}
		$eData['comment'] = $comment;
		$eData['type'] = $type;
		
		$ptype = $comment['type'];
		$this->db->where('id',$comment['belongId']);
		if($ptype == '1'){
			$street = $this->db->get('street')->row_array();
			$eData['street'] = $street;
		}else if($ptype == '2'){
			$store = $this->db->get('store')->row_array();
			$eData['store'] = $store;
			
			$this->db->where('name',$store['storetype']);
			$this->db->where('code',$store['storetypes']);
			$eData['storeType'] = $this->db->get('codevalue')->row_array();
		}
		
		$this->db->select('comment.*,member.username,member.avatar,member.id as memberId');
		$this->db->from('comment');
		$this->db->join('member', 'member.id = comment.creatid');
		$this->db->where('type',$type);
		$this->db->where('belongId',$commentId);
		$this->db->order_by('createtime', 'DESC');
		$this->db->limit(7,$ePage);
		$replyList = $this->db->get()->result_array();
		$eData['replyList'] = $replyList;
		
		$this->db->where('type',$type);
		$this->db->where('belongId',$commentId);
		$eData ['replyListCount'] = $this->db->count_all_results('comment');
		
		$this->load->library ( 'pagination' );
		$eConfig ['per_page'] = 7;
		$eConfig ['num_links'] = 7;
		$eConfig ['base_url'] = site_url ( 'replylist/'.$commentId.'/'.$type.'?1=1');
		$eConfig ['total_rows'] = $eData ['replyListCount'];
		$eConfig ['first_link'] = false;
		$eConfig ['last_link'] = false;
		$eConfig ['next_link'] = '下一页';
		$eConfig ['next_tag_open'] = '<li>';
		$eConfig ['next_tag_close'] = '</li>';
		$eConfig ['prev_link'] = '上一页';
		$eConfig ['prev_tag_open'] = '<li>';
		$eConfig ['prev_tag_close'] = '</li>';
		$eConfig ['num_tag_open'] = '<li>';
		$eConfig ['num_tag_close'] = '</li>';
		$eConfig ['cur_tag_open'] = '<li class="current"><a href="#">';
		$eConfig ['cur_tag_close'] = '</a></li>';
		$this->pagination->initialize ( $eConfig );
		
		$this->load->view('replylist',$eData);		
	}
	
	
	
}

